package com.kaikeba.estack.web.dto;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 接收前端分页查询相关的工具类
 *
 * @Auth xingwan
 * @Date 2020/10/3 1:02
 **/
public class PageDto<T> implements Serializable {

    private static final int DEFAULT_PAGE = 1;

    private static final int DEFAULT_LIMIT = 10;

    /**
     * 数据总数
     */
    private Long count;

    /**
     * 当前页码
     */
    private Integer page;

    /**
     * 每页显示的记录数
     */
    private Integer limit;

    /**
     * 前端传递的查询参数
     */
    private Map<String, Object> search;

    /**
     * 前端传递的排序参数
     */
    private SortDto sort;

    /**
     * 查询到的数据
     */
    private List<T> items;

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public Integer getPage() {
        return page == null ? DEFAULT_PAGE : page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getLimit() {
        return limit == null ? DEFAULT_LIMIT : limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Map<String, Object> getSearch() {
        return search;
    }

    public void setSearch(Map<String, Object> search) {
        this.search = search;
    }

    public SortDto getSort() {
        return sort;
    }

    public void setSort(SortDto sort) {
        this.sort = sort;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    @Override
    public String toString() {
        return "PageDto{" +
                "count=" + count +
                ", page=" + page +
                ", limit=" + limit +
                ", search=" + search +
                ", sort=" + sort +
                ", items=" + items +
                '}';
    }
}
